//
//  LGCancerPatientDetailItemCell.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2024/12/17.
//

#import "LGCancerPatientDetailItemView.h"
#import "LGPatientDetailItemView.h"

#define itemWidth   (Screen_W-viewPix(44))/2.0
#define itemHeight  viewPix(75)
@interface LGCancerPatientDetailItemView()
/**  测评记录 */
@property (nonatomic , strong)LGPatientDetailItemView *recordView;
/**  检查报告 */
@property (nonatomic , strong)LGPatientDetailItemView *inspectionView;
/**  体征监测 */
@property (nonatomic , strong)LGPatientDetailItemView *monitorView;
/**  运动康复 */
@property (nonatomic , strong)LGPatientDetailItemView *sportView;
/**  治疗记录 */
@property (nonatomic , strong)LGPatientDetailItemView *treatView;
/**  呼吸训练统计 */
@property (nonatomic , strong)LGPatientDetailItemView *breathView;

@end

@implementation LGCancerPatientDetailItemView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDiseaseCode:(NSString *)diseaseCode{
    _diseaseCode = diseaseCode;
    //2-肺癌 、 3、6-肺结节-其他 、 4-食管癌 、9-慢性阻塞性肺疾病 、 10-间质性肺疾病 、11-慢性肺源性心脏病 、 12-支气管哮喘 、 13-支气管扩张 、 14-慢性咳嗽 、 15-过敏性疾病
    self.breathView.frame = CGRectMake(viewPix(16), kMaxY(self.monitorView.frame)+viewPix(16), Screen_W-viewPix(32), itemHeight);
    if ([diseaseCode isEqualToString:@"9"] || [diseaseCode isEqualToString:@"10"] || [diseaseCode isEqualToString:@"11"]|| [diseaseCode isEqualToString:@"12"]|| [diseaseCode isEqualToString:@"13"]|| [diseaseCode isEqualToString:@"14"]|| [self.diseaseCode isEqualToString:@"15"]) {
        //显示运动康复
        self.sportView.hidden = NO;
        self.treatView.hidden = YES;
        self.inspectionView.frame = CGRectMake(viewPix(16), kMaxY(self.recordView.frame)+viewPix(16), itemWidth, itemHeight);
        self.monitorView.frame = CGRectMake(kMinX(self.sportView.frame), kMaxY(self.sportView.frame)+viewPix(16), itemWidth, itemHeight);
    }else if ([diseaseCode isEqualToString:@"3"] || [diseaseCode isEqualToString:@"6"]){
        //肺结节、其他 的患者 ， 不显示运动康复和治疗记录
        self.sportView.hidden = YES;
        self.treatView.hidden = YES;
        self.inspectionView.frame = CGRectMake(kMinX(self.sportView.frame), kMinY(self.sportView.frame), itemWidth, itemHeight);
        self.monitorView.frame = CGRectMake(viewPix(16), kMaxY(self.recordView.frame)+viewPix(16), itemWidth, itemHeight);
        self.breathView.frame = CGRectMake(kMinX(self.inspectionView.frame), kMinY(self.monitorView.frame), itemWidth, itemHeight);
    
    }else{
        //显示治疗记录
        self.sportView.hidden = YES;
        self.treatView.hidden = NO;
        self.inspectionView.frame = CGRectMake(kMinX(self.sportView.frame), kMinY(self.sportView.frame), itemWidth, itemHeight);
        self.monitorView.frame = CGRectMake(viewPix(16), kMaxY(self.recordView.frame)+viewPix(16), itemWidth, itemHeight);
    }
}


-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    //测评记录
    NSDictionary *recordDic = [dataDic[@"evas"] isKindOfClass:[NSDictionary class]]?dataDic[@"evas"]:@{};
    if(recordDic.allKeys.count>0){
        NSString *content = [NSString stringWithFormat:@"%@ 更新记录",recordDic[@"date"]];
        self.recordView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, content.length-4)];
    }else{
        self.recordView.contentLabel.attributedText = [@"近30天暂无记录" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 4)];
    }
    
    //运动康复
    NSDictionary *sportDic = [dataDic[@"sport"] isKindOfClass:[NSDictionary class]]?dataDic[@"sport"]:@{};
    if(sportDic.allKeys.count>0){
        NSString *content = [NSString stringWithFormat:@"%@ 更新方案",sportDic[@"date"]];
        self.sportView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, content.length-4)];
    }else{
        self.sportView.contentLabel.attributedText = [@"暂无方案" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 4)];
    }
    
    //检查报告
    NSDictionary *inspectDic = [dataDic[@"exams"] isKindOfClass:[NSDictionary class]]?dataDic[@"exams"]:@{};
    if(inspectDic.allKeys.count>0){
        NSString *date = LGNSString(inspectDic[@"date"]);
        date = [date isEmptyString]?@"":date;
        NSString *content = [NSString stringWithFormat:@"%@ 更新报告",date];
        self.inspectionView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, content.length-4)];
    }else{
        self.inspectionView.contentLabel.attributedText = [@"近30天暂无报告" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 8)];
    }
    
    //体征监测
    NSDictionary *monitorDic = [dataDic[@"monitor"] isKindOfClass:[NSDictionary class]]?dataDic[@"monitor"]:@{};
    if([monitorDic allKeys].count>0){
        NSString *content = [NSString stringWithFormat:@"%@ 血压 %@/%@ %@",monitorDic[@"date"],monitorDic[@"sbp"],monitorDic[@"dbp"],monitorDic[@"pulse"]];
        self.monitorView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#3291FF"]} range:NSMakeRange(8, content.length-8)];
    }else{
        self.monitorView.contentLabel.attributedText = [@"暂无血压记录" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 6)];
    }
    
    //治疗记录
    NSDictionary *treatDic = [dataDic[@"treats"] isKindOfClass:[NSDictionary class]]?dataDic[@"treats"]:@{};
    if([treatDic allKeys].count>0){
        NSString *date = LGNSString(treatDic[@"date"]);
        date = [date isEmptyString]?@"":date;
        NSString *content = [NSString stringWithFormat:@"%@ 更新记录",date];
        self.treatView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, content.length-4)];
    }else{
        self.treatView.contentLabel.attributedText = [@"近30天暂无记录" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 8)];
    }
    
    //呼吸训练
    NSDictionary *breathDic = [dataDic[@"pranayama"] isKindOfClass:[NSDictionary class]]?dataDic[@"pranayama"]:@{};
    if([breathDic allKeys].count>0){
        NSString *date = LGNSString(breathDic[@"date"]);
        date = [date isEmptyString]?@"":date;
        NSString *content = [NSString stringWithFormat:@"%@ 更新记录",date];
        self.breathView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, content.length-4)];
    }else{
        self.breathView.contentLabel.attributedText = [@"暂无训练记录" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 6)];
    }
    
}

-(void)checkItemDetailAction:(UITapGestureRecognizer *)sender{
    CGPoint point = [sender locationInView:self];
    if(CGRectContainsPoint(self.recordView.frame, point)){
        //测评记录
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkEvaluationRecord)]){
            [self.delegate checkEvaluationRecord];
        }
    }else if (([self.diseaseCode isEqualToString:@"9"] || [self.diseaseCode isEqualToString:@"10"]|| [self.diseaseCode isEqualToString:@"11"]|| [self.diseaseCode isEqualToString:@"12"]|| [self.diseaseCode isEqualToString:@"13"]|| [self.diseaseCode isEqualToString:@"14"]|| [self.diseaseCode isEqualToString:@"15"]) && CGRectContainsPoint(self.sportView.frame, point)){
        //运动康复
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkSportsController)]){
            [self.delegate checkSportsController];
        }
    }else if (CGRectContainsPoint(self.inspectionView.frame, point)){
        //检验检测报告
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkInspectionReport)]){
            [self.delegate checkInspectionReport];
        }
    }else if (CGRectContainsPoint(self.monitorView.frame, point)){
        //体征监测
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkMonitorData)]){
            [self.delegate checkMonitorData];
        }
    }else if (CGRectContainsPoint(self.treatView.frame, point) && (![self.diseaseCode isEqualToString:@"3"] && ![self.diseaseCode isEqualToString:@"6"])){
        //治疗记录
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkTreatReocrd)]){
            [self.delegate checkTreatReocrd];
        }
    }else if (CGRectContainsPoint(self.breathView.frame, point)){
        //体征监测
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkBreathRecord)]){
            [self.delegate checkBreathRecord];
        }
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkItemDetailAction:)]];
    [self addSubview:self.recordView];
    [self addSubview:self.sportView];
    [self addSubview:self.treatView];
    [self addSubview:self.inspectionView];
    [self addSubview:self.monitorView];
    [self addSubview:self.breathView];
}

-(LGPatientDetailItemView *)recordView{
    if(!_recordView){
        _recordView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(8), itemWidth, itemHeight)];
        [_recordView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _recordView.backgroundColor = [UIColor whiteColor];
        _recordView.title = @"测评记录";
        _recordView.contentLabel.text = @"暂无记录";
    }
    return _recordView;
}

-(LGPatientDetailItemView *)sportView{
    if(!_sportView){
        _sportView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(kMaxX(self.recordView.frame)+viewPix(16), kMinY(self.recordView.frame), itemWidth, itemHeight)];
        [_sportView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _sportView.backgroundColor = [UIColor whiteColor];
        _sportView.title = @"运动康复";
        _sportView.contentLabel.text = @"暂无方案";
    }
    return _sportView;
}


-(LGPatientDetailItemView *)inspectionView{
    if(!_inspectionView){
        _inspectionView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.recordView.frame)+viewPix(16), itemWidth, itemHeight)];
        [_inspectionView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _inspectionView.backgroundColor = [UIColor whiteColor];
        _inspectionView.title = @"检验检查报告";
        _inspectionView.contentLabel.text = @"近30天暂无报告";
    }
    return _inspectionView;
}

-(LGPatientDetailItemView *)monitorView{
    if(!_monitorView){
        _monitorView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(kMaxX(self.inspectionView.frame)+viewPix(16), kMinY(self.inspectionView.frame), itemWidth, itemHeight)];
        [_monitorView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _monitorView.backgroundColor = [UIColor whiteColor];
        _monitorView.title = @"体征监测";
        _monitorView.contentLabel.text = @"暂无血压记录";
    }
    return _monitorView;
}

-(LGPatientDetailItemView *)treatView{
    if(!_treatView){
        _treatView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(kMinX(self.sportView.frame), kMaxY(self.sportView.frame)+viewPix(16), itemWidth, itemHeight)];
        [_treatView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _treatView.backgroundColor = [UIColor whiteColor];
        _treatView.title = @"治疗记录";
        _treatView.contentLabel.text = @"暂无记录";
    }
    return _treatView;
}

-(LGPatientDetailItemView *)breathView{
    if(!_breathView){
        _breathView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.monitorView.frame)+viewPix(16), Screen_W-viewPix(32), itemHeight)];
        [_breathView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _breathView.backgroundColor = [UIColor whiteColor];
        _breathView.title = @"呼吸训练记录";
        _breathView.contentLabel.text = @"暂无训练记录";
    }
    return _breathView;
}


@end
